<?php
/* @var $this NewsController */
/* @var $model News */
/* @var $form CActiveForm */
?>

<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'news-form',
	'enableAjaxValidation'=>false,
)); ?>
	<?php echo $form->hiddenField($model,'zm_id')?>
	<ul class="form_list form_list2 mt10">
		<li class="c_f"><span class="tit"><em class="xing">*</em>选择类目：</span>
			<div class="cont f_l" id="catagory">
				<select name="Product[cateid1]" class="level_1 s_ipt w_120" id="dataProductIndustryId1" ></select>
				<select name="Product[cateid2]" class="level_2 s_ipt w_120" id="dataProductIndustryId2"></select>
				<select name="Product[cateid3]" class="level_3 s_ipt w_120" id="dataProductIndustryId3" ></select>
				<?php echo $form->error($model,'znc_id'); ?>
			</div>
		</li>
		<li class="c_f"><span class="tit"><em class="xing">*</em>图库标题：</span>
			<div class="cont f_l">
				<?php echo $form->textField($model,'zne_title',array('class'=>'t_ipt w_300','maxlength'=>30)); ?>
				<?php echo $form->error($model,'zne_title'); ?>
			</div>
		</li>
		<li class="c_f"><span class="tit"><em class="xing">*</em>短标题：</span>
			<div class="cont f_l">
				<?php echo $form->textField($model,'zne_short',array('class'=>'t_ipt w_300','maxlength'=>15));?>
				<?php echo $form->error($model,'zne_short'); ?>
			</div>
		</li>
		<li class="c_f"><span class="tit">信息来源：</span>
			<div class="cont f_l">
				<?php echo $form->textField($model,'zne_source',array('class'=>'t_ipt w_300','maxlength'=>50)); ?>
				<?php echo $form->error($model,'zne_source'); ?>
			</div>
		</li>
		<script>
			KindEditor.ready(function(K) {
				var editor = K.editor({
					allowFileManager : true
				});
				K('#J_selectImage').click(function() {
					editor.loadPlugin('multiimage', function() {
						editor.plugin.multiImageDialog({
							clickFn : function(urlList) {
								var div = K('#J_imageView');
								div.html('');
								var put = K('#J_imageinput');
								put.html('');
								K.each(urlList, function(i, data) {									
									div.append('<img src="' + data.url + '" width="50"/>');
									put.append('<input type="hidden" name="News[zne_photo][]" value="' + data.url + '">');
								});
								editor.hideDialog();
							}
						});
					});
				});
			});
		</script>
		<li class="c_f"><span class="tit">图库：</span>
			<div class="cont f_l">
				<input type="button" id="J_selectImage" value="批量上传" />
				<div id="J_imageView"></div>
				<div id="J_imageinput"></div>					
			</div>
		</li>		
		<li class="c_f"><span class="tit"><em class="xing">*</em>图库说明：</span>
			<div class="cont f_l">
				<?php  $this->widget('ext.keditor.KEditor',array(
		            'model'=>$model,  //传入form model
		            'name'=>'zne_content', //设置name
		            'properties'=>array(
		                //设置接收文件上传的action
		                'uploadJson'=>'/Attachment/GetAjax',
		                //设置浏览服务器文件的action，这两个就是上面配置在/admin/default的
		             //   'fileManagerJson'=>'/Attachment/GetAjax',
		                'newlineTag'=>'br',
		                'allowFileManager'=>true,
		                //传值前加js:来标记这些是js代码
		                'afterCreate'=>"js:function() {
		                        K('#ChapterForm_all_len').val(this.count());
		                        K('#ChapterForm_word_len').val(this.count('text'));
		                    }",
		                'afterChange'=>"js:function() {
		                        K('#ChapterForm_all_len').val(this.count());
		                        K('#ChapterForm_word_len').val(this.count('text'));
		                    }",
		            ),
		            'textareaOptions'=>array(
		                'style'=>'width:700px;height:361px;',
		            )
		        )); ?>
				<p class="c_999">上传图片规格：宽度不能超过750px</p>
			</div>
		</li>
		<li class="c_f"><span class="tit">缩略图：</span>
			<div class="shop_logo">
					<?php echo CHtml::image(empty($model->zne_thumb)?'/images/cert_img.jpg':$model->zne_thumb,'',array('id'=>'img1','width'=>'200px','height'=>'200px'))?>
					<?php echo CHtml::link('上传缩略图<b class="mem_bgx left"></b><b class="mem_bgx right"></b>'.CHtml::fileField('image','',array('id'=>'uploadimg1','multiple'=>true)),'javascript:',array('class'=>'mem_bgx link_btn filelink mr20','onclick'=>"uploadimg('1')"))?>
					<?php echo $form->hiddenField($model,'zne_thumb',array('id'=>'proimage1'))?>
			</div>
		</li>		
		<li class="c_f"><span class="tit">是否头条：</span>
			<div class="cont f_l">
				<div class="f_l mr30">
					<?php echo $form->radioButtonList($model,'zne_focus',News::model()->getZneFocus(),array('labelOptions'=>array('class'=>'mr10'),'class'=>'radio'))?>
				</div>
				<div class="f_l"><span class="">是否推荐：
					<?php echo $form->radioButtonList($model,'zne_commend',News::model()->getZneCommend(),array('labelOptions'=>array('class'=>'mr10'),'class'=>'radio'))?>
				</div>
			</div>
		</li>
		<li class="c_f"><span class="tit">标 签：</span>
			<div class="cont f_l">
				<input class="t_ipt w_300" type="text" name="tag" maxlength="50" />
				<span class="c_999">多个标签请用","号或者空格隔开</span>
			</div>
		</li>
		<li class="c_f"><span class="tit">&nbsp;</span>
			<div class="cont f_l"><input class="mem_btn mem_btn20 mr5" type="submit" name="" value="发布图库" /><input class="mem_btn mem_btn07" type="submit" name="" value="取 消" /></div>
		</li>
	</ul>	
<?php $this->endWidget(); ?>

<script type="text/javascript" src="/js/multi_select.js"></script>
<script type="text/javascript">
$.getJSON('/cache/GetNewsCat',function(json){
	var options	= {data	: json};
	var loc = new multi_select(options);
	loc.bind('#catagory .level_1','7');
	loc.bind('#catagory .level_2','<?php if(!empty($model->newscat)) echo ($model->newscat->znc_patentid==0)?'':(($model->newscat->znc_topid==0)?$model->newscat->znc_id:$model->newscat->znc_patentid)?>');
	loc.bind('#catagory .level_3','<?php if(!empty($model->newscat)) echo ($model->newscat->znc_patentid==0)?'':(($model->newscat->znc_topid==0)?'':$model->newscat->znc_patentid)?>');
});
//载入页面显示分类
$(document).ready(function(){
	
	$('.level_2').show();
	$('.level_1').attr('name','');
	$('.level_2').attr('name','News[znc_id]');
	$('.level_3').attr('name','');
	
	if($('.level_3').find('option').length<2){
		$('.level_3').hide();
		$('.level_2').attr('name','News[znc_id]');
		$('.level_3').attr('name','');
	}else{
		$('.level_3').show();
		$('.level_2').attr('name','');
		$('.level_3').attr('name','News[znc_id]');
	}
});

//选行分类 ，链动隐藏
$('.level_1').bind('blur',function(){	
	$('.level_2').show();
	$('.level_1').attr('name','');
	$('.level_2').attr('name','News[znc_id]');
	$('.level_3').attr('name','');
	
	$('.level_3').hide();
});
$('.level_2').bind('blur',function(){
	if($('.level_3').find('option').length<2){
		$('.level_3').hide();
		$('.level_2').attr('name','News[znc_id]');
		$('.level_3').attr('name','');
	}else{
		$('.level_3').show();
		$('.level_2').attr('name','');
		$('.level_3').attr('name','News[znc_id]');
	}
});
</script>

<script src="<?php echo Yii::app()->baseUrl;?>/js/jquery.ui.widget.js"></script>  
<script src="<?php echo Yii::app()->baseUrl;?>/js/jquery.iframe-transport.js"></script>  
<script src="<?php echo Yii::app()->baseUrl;?>/js/jquery.fileupload.js"></script>  

<script>  
//上传图片
function uploadimg (id) {
	   $('#uploadimg'+id).fileupload({         	
	        dataType: 'json',       
	        url: '/Attachment/GetAjax',        
	        success: function (json) {
	               if(json.upfile.errors=='1'){
	               		alert(json.upfile.msg);
	               }else if(json.upfile.errors=='2'){
	               		alert(json.upfile.msg);
	               }else{
		                 //修改按钮图标
		            	 $('#img'+id).attr('src',json.upfile.file);
						 //修改按钮文本
		            	 $('#uploadimg'+id).parent().html('修改图片<b class="mem_bgx left"></b><b class="mem_bgx right"></b><input type="file" id="uploadimg'+id+'" multiple name="image"/>');
		            	 //填加删除按钮
		            	 if(!$('#img'+id).parent().parent().find('a')[1]){
		            		 $('#img'+id).parent().parent().find('a').eq(0).after('<a class="mem_bgx link_btn" href="javascript:" onclick="removeimg(\''+id+'\')">删除图片<b class="mem_bgx left"></b><b class="mem_bgx right"></b></a>');
		            	 }
						 //修改隐藏域值
	               		 $('#proimage'+id).attr('value',json.upfile.file);
	               } 	
	        }
	    });
};
//删除图片
function removeimg(id){
	$('#img'+id).parent().parent().find('a').eq(0).html('上传图片<b class="mem_bgx left"></b><b class="mem_bgx right"></b><input type="file" id="uploadimg'+id+'" multiple name="image"/>');
	$('#img'+id).parent().parent().find('a').eq(1).remove();
	$('#img'+id).attr('src','/images/cert_img.jpg');
	$('#proimage'+id).attr('value','');
}


</script>